package com.example.service;

import com.example.entity.SysResults;
import com.example.exception.CustomException;
import com.example.mapper.SysResultMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysResultService {

    @Resource
    private SysResultMapper sysResultMapper;

    public List<SysResults> selectAll(SysResults sysResults) {
        return sysResultMapper.selectAll(sysResults);
    }

    //分页查询
    public PageInfo<SysResults> selectPage(SysResults sysResults, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysResults> list = sysResultMapper.selectAll(sysResults);
        return PageInfo.of(list);
    }

    public void add(SysResults sysResults) {
        sysResultMapper.insert(sysResults);
    }

    public void update(SysResults sysResults) {
        sysResultMapper.update(sysResults);
    }

    public void delete(Integer id) {
        sysResultMapper.delete(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            sysResultMapper.delete(id);
        }
    }


    public SysResults login(SysResults sysResults) {
        String studentName = sysResults.getStudentName();
        SysResults dbstudent = sysResultMapper.selectByName(studentName);
        if(dbstudent == null) {
            throw new CustomException("500","名字错误");
        }
        return dbstudent;
    }
}
